package com.argrace.smart.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.aliyun.alink.business.devicecenter.api.add.DeviceInfo;
import com.argrace.smart.R;
import com.argrace.smart.glide.GliderImageLoaderUtil;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.ArrayList;

/**
 * Created by argrace_dev_1 on 2018/1/30.
 */

public class DeviceAdapter extends BaseQuickAdapter<DeviceInfo, BaseViewHolder> {
    private Context context;

    public DeviceAdapter(ArrayList<DeviceInfo> data, Context context) {
        super(R.layout.item_activity_main_device, data);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, final DeviceInfo item, final int position) {
        ImageView img = baseViewHolder.getView(R.id.item_activity_main_device_img);
        GliderImageLoaderUtil.loadRoundMore(context, item.productIcon, img);
        baseViewHolder.setText(R.id.item_activity_main_device_name, item.productName);
        baseViewHolder.setText(R.id.item_activity_main_device_macaddr, item.mac);
        baseViewHolder.getView(R.id.item_activity_main_device_ll).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.click(item, position);
            }
        });
        baseViewHolder.getView(R.id.item_activity_main_device_ll).setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                longlistener.click(item, position);
                return true;
            }
        });
    }

    private OnAdapterItemClickListener listener;

    public interface OnAdapterItemClickListener {
        void click(DeviceInfo bean, int position);
    }

    public void setListeners(OnAdapterItemClickListener l) {
        this.listener = l;
    }

    private OnAdapterItemLongClickListener longlistener;

    public interface OnAdapterItemLongClickListener {
        void click(DeviceInfo bean, int position);
    }

    public void setlongListeners(OnAdapterItemLongClickListener l) {
        this.longlistener = l;
    }


}
